package com.example.supermarket.controller;

import com.example.supermarket.pojo.*;
import com.example.supermarket.service.CustomerService;
import org.mockito.internal.matchers.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PostMapping("/createOrder")
    public Result<Integer> createOrder(@RequestBody Order order){
        customerService.createOrder(order);
        Integer orderId=customerService.findOrderId(order);
        return Result.success(orderId);
    }

    @PostMapping("/createLineItem")
    public Result createLineItem(@RequestBody LineItem lineItem){
        customerService.createLineItem(lineItem);
        return Result.success();
    }

    @GetMapping("/getCustomerInfo")
    public Result<Customer> getCustomerInfo(){
        Customer customer=customerService.getCustomerInfo();
        return Result.success(customer);
    }

    @GetMapping("/findCustomerOrder")
    public Result<Order> findCustomerOrder(Integer shopId){
        Order order=customerService.findCustomerOrder(shopId);
        return Result.success(order);
    }

    @GetMapping("/findItemByOrderId")
    public Result<List<LineItem>> findItemByOrderId(Integer orderId){
        List<LineItem> list=customerService.findItemByOrderId(orderId);
        return Result.success(list);
    }

    @GetMapping("/findOrderByOrderId")
    public Result<Order> findOrderByOrderId(Integer orderId){
        Order order=customerService.findOrderByOrderId(orderId);
        return Result.success(order);
    }

    @PostMapping("/deleteOrder")
    public Result deleteOrder(Integer orderId){
        customerService.deleteOrder(orderId);
        return  Result.success();
    }

    @PostMapping("/payOrder")
    public Result payOrder(Integer orderId){
        customerService.payOrder(orderId);
        return Result.success();
    }

    @GetMapping("/findHistoryOrder")
    public Result<List<Order>> findHistoryOrder(){
        List<Order> list=customerService.findHistoryOrder();
        return Result.success(list);
    }

    @GetMapping("/getCustomerByCustomerId")
    public Result<Customer> getCustomerByCustomerId(Integer customerId){
        Customer customer=customerService.getCustomerByCustomerId(customerId);
        return Result.success(customer);
    }

}
